use crate::components::{LoginForm, Prompt};
use crate::message::{MessageContext, MessageProvider, MsgAction};
use gloo::console;
//use web_sys::HtmlInputElement;
use yew::prelude::*;

#[function_component(Root)]
fn root() -> Html {
    let msg = use_context::<MessageContext>().expect("root:no context");

    let handle_confirm = {
        let msg = msg.clone();
        Callback::from(move |_| {
            msg.dispatch(MsgAction::HideMsg);
            console::log!("confirm");
        })
    };
    html! {
        <div class={classes!("column", "align-center", "content-center", "w-100")}>
            <LoginForm/>
        {
           if msg.msg_show {
            html!{
                <Prompt msg={msg.msg_txt.clone()} on_confirm={handle_confirm}/>
                }
                    } else {
            html!{}
           }
        }
        </div>
    }
}

#[function_component(App)]
pub fn app() -> Html {
    html! {
        <MessageProvider>
            <Root/>
        </MessageProvider>
    }
}

/*
 *
*/
//https://github.com/futursolo/stylist-rs/blob/master/examples/yew-theme-context/src/contexts/theme.rs
